<?php

namespace app\admin\model;

use think\Model;

/**
 * Peiwu
 */
class Peiwu extends Model
{
    // 表名
    protected $name = 'peiwu';

    // 自动写入时间戳字段
    protected $autoWriteTimestamp = false;

    protected $append = ['m1_name', 'm2_name'];


    public function m1Table(): \think\model\relation\BelongsTo
    {
        return $this->belongsTo(\app\admin\model\Medicine::class, 'm1', 'id');
    }

    public function m2Table(): \think\model\relation\BelongsTo
    {
        return $this->belongsTo(\app\admin\model\Medicine::class, 'm2', 'id');
    }

    public function getM1NameAttr($value, $data)
    {
        return Medicine::where('id', $data['m1'])->value('name');
    }
    public function getM2NameAttr($value, $data)
    {
        return Medicine::where('id', $data['m2'])->value('name');
    }
}
